package me.baicai.weixin.identity.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import me.baicai.weixin.identity.service.AgentService;
import me.baicai.weixin.application.Result;
import me.baicai.weixin.entity.config.ShopMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 关于用户的公共API部分
 */

@Api(tags = "代理操作：代理操作")
@RestController
public class AgentController
{

    @Autowired
    AgentService agentService;

    @ApiOperation("代理首页")
    @ApiImplicitParam(value = "openid", name = "openid", required = true, dataType = "String")
    @PostMapping("/agent/agentIndex")
    public Result agentIndex(@RequestHeader("openid") String openid)
    {
        return agentService.agentIndex(openid);
    }

    @ApiOperation("下级代理管理")
    @ApiImplicitParam(value = "openid", name = "openid", required = true, dataType = "String")
    @PostMapping("/agent/agentChild")
    public Result agentChild(@RequestHeader("openid") String openid,
                             @RequestParam("page") int page,
                             @RequestParam(value = "input", required = false) String input)
    {
        return agentService.agentChild(openid, page, input);
    }

    @ApiOperation("下级店铺管理")
    @ApiImplicitParam(value = "openid", name = "openid", required = true, dataType = "String")
    @PostMapping("/agent/agentShop")
    public Result agentShop(@RequestHeader("openid") String openid,
                            @RequestParam("page") int page,
                            @RequestParam(value = "input", required = false) String input)
    {
        return agentService.agentShop(openid, page, input);
    }

    @ApiOperation("下级设备管理")
    @PostMapping("/agent/agentDevice")
    public Result agentDevice(@RequestHeader("openid") String openid,
                              @RequestParam("page") int page,
                              @RequestParam(value = "input", required = false) String input)
    {
        return agentService.agentDevice(openid, page, input);
    }

    @ApiOperation("店铺详情")
    @PostMapping("/agent/shopInfo")
    public Result shopInfo(@RequestParam("id") Integer id)
    {
        return agentService.shopInfo(id);
    }

    @ApiOperation("提交店铺信息修改")
    @PostMapping("/agent/submitShopInfo")
    public Result submitShopInfo(@RequestParam("id") Integer id,
                                 @RequestParam("name") String name,
                                 @RequestParam("tel") String tel,
                                 @RequestParam("address") String address,
                                 @RequestParam("commission") Integer commission,
                                 @RequestParam("latitude") String latitude,
                                 @RequestParam("longitude") String longitude,
                                 @RequestParam(value = "refund",required = false, defaultValue = "5") Integer refund)
    {
        return agentService.submitShopInfo(id, name, tel, address, commission, refund,latitude,longitude);
    }

    @ApiOperation("提交店铺信息修改")
    @PostMapping("/agent/submitAgentInfo")
    public Result submitAgentInfo(@RequestParam("id") Integer id,
                                  @RequestParam("name") String name,
                                  @RequestParam("tel") String tel,
                                  @RequestParam("address") String address,
                                  @RequestParam("commission") Integer commission)
    {
        return agentService.submitAgentInfo(id, name, tel, address, commission);
    }

    @ApiOperation("店铺套餐查询")
    @PostMapping("/agent/shopMenu")
    public Result shopMenu(@RequestParam("id") Integer id)
    {
        return agentService.shopMenu(id);
    }

    @ApiOperation("店铺套餐修改")
    @PostMapping("/agent/sumbitShopMenu")
    public Result sumbitShopMenu(@RequestBody List<ShopMenu> list)
    {
        return agentService.sumbitShopMenu(list);
    }

    @ApiOperation("店铺设备查看")
    @PostMapping("/agent/shopDevice")
    public Result shopDevice(@RequestParam("id") Integer id,
                             @RequestParam("page") int page,
                             @RequestParam(value = "input", required = false) String input)
    {
        return agentService.shopDevice(id, page, input);
    }

    @ApiOperation("设备删除")
    @PostMapping("/agent/deleteDevice")
    public Result deleteDevice(@RequestParam("sn") String sn)
    {
        return agentService.deleteDevice(sn);
    }

    @ApiOperation("设备房间号修改")
    @PostMapping("/agent/updateDeviceRemark")
    public Result updateDeviceRemark(@RequestParam("sn") String sn,
                                     @RequestParam("remark") String remark)
    {
        return agentService.updateDeviceRemark(sn, remark);
    }

    @ApiOperation("设备描述修改")
    @PostMapping("/agent/updateDeviceDesc")
    public Result updateDeviceDesc(@RequestParam("sn") String sn,
                                     @RequestParam("desc") String desc)
    {
        return agentService.updateDeviceDesc(sn, desc);
    }

    @ApiOperation("添加设备")
    @PostMapping("/agent/submitDevice")
    public Result submitDevice(@RequestParam("sn") String sn,
                               @RequestParam("shopid") Integer shopid,
                               @RequestParam("version") Integer version,
                               @RequestParam("remark") String remark)
    {
        return agentService.submitDevice(sn, remark, shopid, version);
    }

    @ApiOperation("添加下级代理")
    @PostMapping("/agent/submitAgent")
    public Result submitAgent(@RequestHeader("openid") String openid,
                              @RequestParam("id") Integer id,
                              @RequestParam("name") String name,
                              @RequestParam("tel") String tel,
                              @RequestParam("address") String address,
                              @RequestParam("commission") Integer commission)
    {
        return agentService.submitAgent(openid, id, name, tel, address, commission);
    }

    @ApiOperation("添加下级店铺")
    @PostMapping("/agent/submitShop")
    public Result submitShop(@RequestHeader("openid") String openid,
                             @RequestParam("shopName") String shopName,
                             @RequestParam("tel") String tel,
                             @RequestParam("address") String address,
                             @RequestParam("commission") Integer commission,
                             @RequestParam("id") Integer id,
                             @RequestParam("latitude") String latitude,
                             @RequestParam("longitude") String longitude,
                             @RequestParam("name") String name,
                             @RequestParam(value = "refund", required = false, defaultValue = "5") Integer refund)
    {
        return agentService.submitShop(openid, shopName, tel, address, commission, id, name, refund,latitude,longitude);
    }

    @ApiOperation("查询校验这个ID")
    @PostMapping("/agent/verifyShopID")
    public Result verifyShopID(@RequestParam("id") Integer id)
    {
        return agentService.verifyShopID(id);
    }

    @ApiOperation("收入统计")
    @PostMapping("/agent/incomeStatistics")
    public Result incomeStatistics(@RequestHeader("openid") String openid,
                                   @RequestParam("page") Integer page,
                                   @RequestParam("type") String type)
    {
        return agentService.incomeStatistics(openid, page, type);
    }

    @ApiOperation("代理设备管理")
    @PostMapping("/agent/agentDeviceInfo")
    public Result agentDeviceInfo(@RequestHeader("openid") String openid,
                                  @RequestParam("page") Integer page,
                                  @RequestParam("input") String input)
    {
        return agentService.agentDeviceInfo(openid, page, input);
    }

    @ApiOperation("代理设备管理")
    @PostMapping("/agent/getAgentShop")
    public Result getAgentShop(@RequestHeader("openid") String openid)
    {
        return agentService.getAgentShop(openid);
    }

    @ApiOperation("人员管理")
    @PostMapping("/agent/getAgentEmployee")
    public Result getAgentEmployee(@RequestHeader("openid") String openid,
                                   @RequestParam("type") String type)
    {
        return agentService.getAgentEmployee(openid, type);
    }

    @ApiOperation("添加员工")
    @PostMapping("/agent/submitEmployee")
    public Result submitEmployee(@RequestHeader("openid") String openid,
                                 @RequestParam("name") String name,
                                 @RequestParam("id") Integer id,
                                 @RequestParam("type") String type,
                                 @RequestParam("telphone") String telphone,
                                 @RequestParam("remark") String remark)
    {
        return agentService.submitEmployee(openid, name, id, type, telphone, remark);
    }

    @ApiOperation("删除员工")
    @PostMapping("/agent/deleteEmployee")
    public Result deleteEmployee(@RequestHeader("openid") String openid,
                                 @RequestParam("id") Integer id,
                                 @RequestParam("newId") Integer newId,
                                 @RequestParam("type") String type)
    {
        return agentService.deleteEmployee(openid, id, newId, type);
    }

    @ApiOperation("修改员工店铺")
    @PostMapping("/agent/updateEmployee")
    public Result updateEmployee(@RequestHeader("openid") String openid,
                                 @RequestParam("id") Integer id,
                                 @RequestParam("shop") String shop,
                                 @RequestParam("type") String type)
    {
        return agentService.updateEmployee(openid, id, shop, type);
    }

    @ApiOperation("查询代理下面的店铺列表")
    @PostMapping("/agent/getAgentShopList")
    public Result getAgentShopList(@RequestHeader("openid") String openid,
                                   @RequestParam("type") String type)
    {
        return agentService.getAgentShopList(openid, type);
    }

    @ApiOperation("代理设备下的订单详情")
    @PostMapping("/agent/getDeviceOrder")
    public Result getDeviceOrder(@RequestParam("sn") String sn,
                                 @RequestParam("page") Integer page)
    {
        return agentService.getDeviceOrder(sn, page);
    }

    @ApiOperation("商家单日收入订单列表")
    @PostMapping("/agent/orderStatistics")
    public Result orderStatistics(@RequestHeader("openid") String openid,
                                  @RequestParam("date") String date)
    {
        return agentService.orderStatistics(openid, date);
    }

    @ApiOperation("统计分析使用的日期工具")
    @PostMapping("/agent/getDate")
    public Result getDate()
    {
        return agentService.getDate();
    }

    @ApiOperation("使用分析-代理")
    @PostMapping("/agent/usageAnalysisByAgent")
    public Result usageAnalysisByAgent(@RequestParam("openid") String openid,
                                       @RequestParam("date") String date,
                                       @RequestParam("page") Integer page,
                                       @RequestParam("sort") String sort,
                                       @RequestParam("type") String type,
                                       @RequestParam("input") String input)
    {
        return agentService.usageAnalysisByAgent(openid, date, page, sort, type, input);
    }

    @ApiOperation("使用分析-商店")
    @PostMapping("/agent/usageAnalysisByShop")
    public Result usageAnalysisByShop(@RequestParam("openid") String openid,
                                      @RequestParam("date") String date,
                                      @RequestParam("page") Integer page,
                                      @RequestParam("sort") String sort,
                                      @RequestParam("type") String type,
                                      @RequestParam("input") String input)
    {
        return agentService.usageAnalysisByShop(openid, date, page, sort, type, input);
    }

    @ApiOperation("使用分析-设备")
    @PostMapping("/agent/usageAnalysisByDevice")
    public Result usageAnalysisByDevice(@RequestParam("openid") String openid,
                                        @RequestParam("date") String date,
                                        @RequestParam("page") Integer page,
                                        @RequestParam("sort") String sort,
                                        @RequestParam("type") String type,
                                        @RequestParam("input") String input)
    {
        return agentService.usageAnalysisByDevice(openid, date, page, sort, type, input);
    }

    @ApiOperation("使用分析-代理-店铺详情")
    @PostMapping("/agent/usageAnalysisByShopInfo")
    public Result usageAnalysisByShopInfo(@RequestParam("openid") String openid,
                                          @RequestParam("date") String date,
                                          @RequestParam("id") Integer id,
                                          @RequestParam("type") String type)
    {
        return agentService.usageAnalysisByShopInfo(openid, date, id, type);
    }

    @ApiOperation("设备下的所有订单")
    @PostMapping("/agent/deviceOrderInfo")
    public Result deviceOrderInfo(@RequestParam("openid") String openid,
                                  @RequestParam("sn") String sn,
                                  @RequestParam("page") Integer page)
    {
        return agentService.deviceOrderInfo(openid, sn, page);
    }

    @ApiOperation("删除一个店铺")
    @PostMapping("/agent/deleteShop")
    public Result deleteShop(@RequestHeader("openid") String openid,
                             @RequestParam("oldid") Integer oldid,
                             @RequestParam("newid") Integer newid)
    {
        return agentService.deleteShop(openid, oldid, newid);
    }

    @ApiOperation("修改打工仔姓名")
    @PostMapping("/agent/updateEmpName")
    public Result updateEmpName(@RequestHeader("openid") String openid,
                                @RequestParam("id") Integer id,
                                @RequestParam("name") String name,
                                @RequestParam("telphone") String telphone)
    {
        return agentService.updateEmpName(openid, id, name, telphone);
    }

    @ApiOperation("店铺关联人员查看")
    @PostMapping("/agent/shopStaff")
    public Result shopStaff(@RequestHeader("openid") String openid,
                            @RequestParam("id") Integer id)
    {
        return agentService.shopStaff(openid, id);
    }

    @ApiOperation("店铺关联人员添加")
    @PostMapping("/agent/submitShopStaff")
    public Result submitShopStaff(@RequestHeader("openid") String openid,
                                  @RequestParam("type") String type,
                                  @RequestParam("id") Integer id,
                                  @RequestParam("uid") Integer uid,
                                  @RequestParam("commission") Integer commission,
                                  @RequestParam("name") String name
    )
    {
        return agentService.submitShopStaff(openid, id, uid, type, commission, name);
    }


    @ApiOperation("所有订单")
    @PostMapping("/agent/allOrders")
    public Result allOrders(@RequestParam("value") String value, @RequestParam("start") String start, @RequestParam("end") String end, @RequestParam("page") int page){
        return agentService.allOrders(value, start, end, page);
    }

    @ApiOperation("所有店铺")
    @PostMapping("/agent/allShop")
    public Result allShop(@RequestParam("level") int level, @RequestParam("value") String value, @RequestParam("page") int page){
        return agentService.allShop(level, value, page);
    }

    @ApiOperation("所有代理")
    @PostMapping("/agent/allAgent")
    public Result allAgent(@RequestParam("level") int level, @RequestParam("value") String value, @RequestParam("page") int page){
        return agentService.allAgent(level, value, page);
    }

    @ApiOperation("提现统计数据")
    @PostMapping("/weixin/withdrawal")
    public Result withdrawal(){
        return agentService.withdrawal();
    }
}
